﻿<Table DataSource="data" Bordered HidePagination>
  <PropertyColumn Title="Name" Property="c=>c.name"></PropertyColumn>
  <PropertyColumn Title="Borrow" Property="c=>c.borrow"></PropertyColumn>
  <PropertyColumn Title="Repayment" Property="c=>c.repayment"></PropertyColumn>
  @{
    var totalBorrow = data.Sum(x => x.borrow);
    var totalRepayment = data.Sum(x => x.repayment);
  }
  <SummaryRow>
    <SummaryCell>Total</SummaryCell>
    <SummaryCell>
      <Text Type="TextElementType.Danger">@totalBorrow</Text>
    </SummaryCell>
    <SummaryCell>
      <Text Type="TextElementType.Danger">@totalRepayment</Text>
    </SummaryCell>
  </SummaryRow>
  <SummaryRow>
    <SummaryCell>Balance</SummaryCell>
    <SummaryCell ColSpan="2">
      <Text Type="TextElementType.Danger">@(totalBorrow - totalRepayment)</Text>
      </SummaryCell>
    </SummaryRow>
  </Table>

  <br />

  <Table DataSource="fixedData" ScrollX="2000" Bordered HidePagination>
    <PropertyColumn Title="Name" Property="c=>c.name" Fixed="ColumnFixPlacement.Left" Width="100" />
    <PropertyColumn Title="Description" Property="c=>c.description" />
    <SummaryRow>
      <SummaryCell Fixed="ColumnFixPlacement.Left">Summary</SummaryCell>
      <SummaryCell>This is a summary content</SummaryCell>
    </SummaryRow>
  </Table>

  @code {

  record Data(string key, string name, int borrow, int repayment);

  Data[] data = new Data[]
  {
        new("1","John Brown",10,33),
        new("2","Jim Green",100,0),
        new("3","Joe Black",10,10),
        new("4","Jim Red",75,45),
  };

  record FixedData(string name, string description);

  FixedData[] fixedData = Enumerable.Range(0, 6)
      .Select(i => new FixedData(
             name: (i % 2) > 0 ? "Light" : "Bamboo",
             description: "Everything that has a beginning, has an end.")
      ).ToArray();
}

